Add shell aliases feature to devbox.json#2835
Merged
Merged
Conversation
Add a shell.aliases map to devbox.json that lets users define shell aliases declaratively instead of hand-writing them in the init_hook. Aliases are injected into the devbox shell after the init hook is sourced, so they can rely on anything the hook sets up. They use the shell's builtin alias command, which is compatible across bash, zsh, and fish. Values are single-quoted and escaped per-shell so they are passed verbatim. - configfile: add Aliases to shell config + accessor - config: add merged Aliases() accessor (root overrides included) - shell: render alias lines (sorted, escaped) into the shellrc - shellrc.tmpl / shellrc_fish.tmpl: emit aliases after hooks are sourced - schema: document shell.aliases - tests for parsing, merging, rendering, and escaping
Promote aliases from shell.aliases to a top-level "aliases" key in devbox.json. Behavior is unchanged: aliases are still injected into the devbox shell after the init hook is sourced.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds declarative shell alias support to devbox configuration and renders configured aliases into generated shell startup files after the init hook.
Changes:
- Adds alias storage/accessors in devconfig and merge behavior across included configs.
- Renders deterministic, shell-escaped alias commands for POSIX shells and fish.
- Updates schema and tests for alias parsing/rendering behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
internal/devconfig/configfile/file.go |
Adds alias configuration field to parsed config. |
internal/devconfig/config.go |
Adds merged Aliases() accessor. |
internal/devconfig/config_test.go |
Tests alias parsing and empty alias behavior. |
internal/devbox/shell.go |
Generates sorted alias command lines with shell-specific quoting. |
internal/devbox/shell_test.go |
Tests shellrc alias rendering and placement after hooks. |
internal/devbox/shellrc.tmpl |
Emits aliases in POSIX shellrc template. |
internal/devbox/shellrc_fish.tmpl |
Emits aliases in fish shellrc template. |
.schema/devbox.schema.json |
Documents the new aliases configuration property. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| lines := make([]string, 0, len(names)) | ||
| for _, name := range names { | ||
| lines = append(lines, fmt.Sprintf("alias %s=%s", name, s.quoteAliasValue(aliases[name]))) |
Collaborator
Author
There was a problem hiding this comment.
Good catch. Added a validateAliases check (mirroring validateScripts) that runs at config load time and rejects aliases with empty/whitespace names or empty commands, so they can no longer render invalid alias syntax at shell startup. Fixed in 39c156a, with tests covering each invalid case.
Generated by Claude Code
Reject aliases with empty/whitespace names or empty commands at config load time, so they can't render invalid shell syntax (e.g. "alias =..." or "alias bad name=...") at shell startup. Mirrors script name validation.
Lagoja
approved these changes
Jun 1, 2026
Make aliases defined in devbox.json runnable with `devbox run <alias>`, not just inside the interactive shell. When the run target isn't a script, it's expanded against the merged aliases (mirroring how a shell expands an alias in command position), so aliases work even when the init hook hasn't defined them. Arguments are passed through. Also demonstrate plugin aliases + parent override in the local plugin example, with a test asserting the merged result, plus a run testscript exercising `devbox run <alias>` and argument passthrough.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a top-level
aliasesmap to devbox.json that lets users define shellaliases declaratively instead of hand-writing them in the init_hook.
{ "shell": { "init_hook": "echo welcome" }, "aliases": { "ll": "ls -la", "gs": "git status" } }In the interactive shell (
devbox shell), aliases are injected after theinit hook is sourced, so they can rely on anything the hook sets up. They use
the shell's builtin
aliascommand, which is compatible across bash, zsh, andfish. Values are single-quoted and escaped per-shell so they are passed
verbatim.
Via
devbox run,devbox run <alias>expands the alias to its command andruns it (with any extra args passed through), mirroring how a shell expands an
alias in command position. This means aliases work without an interactive shell
— i.e. even when the init hook hasn't defined them.
Aliases merge across included plugins and the parent config, with the parent
overriding plugin-defined aliases (same precedence as
env/scripts).aliasesfield + validation (no empty/whitespace names, no empty commands)Aliases()accessor (root overrides included)devbox run <alias>to the alias commandaliaseskeydevbox run <alias>